#!/usr/bin/python
from subprocess import Popen, PIPE
from sys import argv, exit

color = { "tls1" : "\033[95m", "ssl2" : "\033[1;91m", "ssl3" : "\033[1;93m", 
    "matrix": "\033[92m", "norm" : "\033[0m" }
resp = { "ssl2": "", "ssl3": "", "tls1": "" }

if len(argv) < 2:
    print "Usage: %s [hostname|ip] {port (default: 443)}"
    exit(0)
else: host = argv[1]
if len(argv) < 3:
    port = "443"
else: port = argv[2]
methods = ["ssl2", "ssl3", "tls1"]
print "[+] Testing %s%s:%s%s SSL Cipher Strength." % (color["matrix"], host, port, color["norm"])
for v in methods:
    ciphers = Popen(["openssl", "ciphers", "-%s" % v],  stdout=PIPE).communicate()[0].rstrip().split(":")
    print color[v] + v.upper() + color["norm"] + " (%s total ciphers)"% len(ciphers),
    for c in ciphers:
    	results = Popen(["openssl", "s_client", "-" + v, "-cipher", c, "-connect", "%s:%s" % (host,port)],
      		stdin=PIPE, stderr=PIPE, stdout=PIPE)
    	results.stdin.write("\r\n\r\n")
    	rc = results.communicate()[0]
    	if "New" in rc:
    		if not "(NONE)" in rc:
    			resp[v] += c + " "
    if resp[v]:
    	print "- Supported Ciphers: %s%s%s" % (color[v], resp[v], color["norm"])
    else: 				
    	print "- Supported Ciphers: %sNONE%s" % (color[v], color["norm"]) 
